package com.znufe.exam.controller.student;

import com.github.pagehelper.PageInfo;
import com.znufe.exam.base.RestResponse;
import com.znufe.exam.domain.classes.StudentClassResponseObject;
import com.znufe.exam.service.StudentClassService;
import com.znufe.exam.utility.PageInfoHelper;
import com.znufe.exam.viewmodel.admin.classes.StudentClassPageRequestVM;
import com.znufe.exam.viewmodel.admin.classes.StudentClassResponseVM;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@Api(description = "班级信息表",value="班级信息表" )
@RestController("UserStudentClassController")
@RequestMapping(value="api/user/student_class")
public class StudentClassController {

    @Autowired
    public StudentClassService studentClassService;

    @RequestMapping(value = "/page", method = RequestMethod.POST)
    @ApiOperation(value = "学生班级表的页面查询接口（无参数查找/按班级名称查找）",
            notes = "查询班级信息[student_class]，作者：lin keqing")
    public RestResponse<PageInfo<StudentClassResponseVM>> pageList(@RequestBody StudentClassPageRequestVM model) {
        model = StudentClassPageRequestVM.wipeBlank(model);
        PageInfo<StudentClassResponseObject> pageInfo = studentClassService.studentClassPage(model);
        PageInfo<StudentClassResponseVM> page = PageInfoHelper.copyMap(pageInfo,
                d -> {
                    StudentClassResponseVM vm = StudentClassResponseVM.from(d);
                    //Integer stuCount = studentClassService.selectClassStuCountById(vm.getId());
                    //vm.setStuCount(stuCount);
                    return vm;
                });
        return RestResponse.ok(page);

    }
}
